#include "qimageprocessing.h"
#include <qstring.h>
#include <qline.h>
#include <QDebug>

using namespace std;

QImageProcessing* QImageProcessing::m_instance = NULL;

QImageProcessing::QImageProcessing():
    QObject(0)
{
}

QImageProcessing *QImageProcessing::instance()
{
    if(m_instance == NULL)
        m_instance = new QImageProcessing();
    return m_instance;
}

bool QImageProcessing::sortLinesHori(float line1, float line2)
{
    return false;
}

void QImageProcessing::traitementimage(cv::Mat &img)
{
    cv::Mat dst;
    Canny( img, dst, 45, 45*3, 3 );
    std::vector<cv::Vec4i> lines;
    QList<QLineF> lignes;
    cv::HoughLinesP(dst,lines, 1, CV_PI/180,80,30,10);

    for( size_t i = 0; i < lines.size(); i++ )
    {
        lignes << QLineF(lines[i][0],lines[i][1],lines[i][2],lines[i][3]);
        cv::line( img, cv::Point(lines[i][0], lines[i][1]),
            cv::Point(lines[i][2], lines[i][3]), cv::Scalar(0,0,255), 1, 8 );
        emit envoi_txt(QString("%1 %2 %3 %4 %5 ").arg(lignes[i].x1()).arg(lignes[i].y1()).arg(lignes[i].x2()).arg(lignes[i].y2()).arg(lignes[i].angle()).toUtf8());
       // test commit
    }
    cv::putText(img,QString("%1,%2").arg(img.cols).arg(img.rows).toStdString(),cv::Point2i(40,40),CV_FONT_HERSHEY_PLAIN ,1,cv::Scalar(255,0,255),1,8);
}

